
module.exports = function ($scope, $state, $stateParams,$resource,$modal,FileUploader,toaster) {
    $scope.getCompanyInfo = function () {
        $resource('/api/ac/ggc/reviewCompanyService/getApplyCompanyInfo', {}, {}).save({}, function(res){
            if(res.errcode != 0){ 
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            console.log('查询企业信息是否完整');
            console.log(res);
            if (res.data.msg == '0') {
              if (confirm('请先完善企业信息')) {
                $state.go('app.completeinfo');
              } else {
                $state.go('app.completeinfo');
              }
            }
        });
    }
    $scope.getCompanyInfo();
    $scope.notice = {
      'info' : {}
    }
    $scope.a = {
      'project_name' : '',
      'project_file' : '',
      'recommend_type': '', // 责任处室
      'project_type' : '', //项目类别(公告类型)
      'city_project' : '', // 是否为本市项目
      'company_code_name' : ''
    };
    $scope.getNoticeList = function(){
        $resource('/api/as/ggc/reviewGuide/findCompanysList', {}, {}).save({}, function(res){
            if(res.errcode != 0){ 
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            console.log(res);
            $scope.noticeArr = res.data;
        });
    }
    // 所属区县
    $resource('/api/as/ggc/reviewCompany/getCompanyCity', {}, {}).save({}, function(res){
        if(res.errcode != 0){ 
            toaster.error({title:"",body:res.errmsg});
            return;
        }
        console.log(res);
        $scope.a.company_code_name = res.data.company_code_name;
    });
    $scope.getNoticeList();
    $scope.change = function(aa){
      console.log(aa);
      $scope.a.guide_name = aa.guide_name;
      $scope.a.project_type = aa.guide_type;
      $scope.a.city_project = aa.city_project;
      $scope.a.recommend_type = aa.recommend_type;
      $scope.a.project_build = aa.project_build;
      $scope.a.project_level = aa.project_level;
      $scope.getRecommendName($scope.a.recommend_type);
      $scope.getGuideType(aa.guide_type);
      if(aa.project_build == '1'){
        $scope.a.project_build_name = '非建设类';
      } else if(aa.project_build == '0') {
        $scope.a.project_build_name = '建设类';
      }
      if(aa.project_level == '1'){
        $scope.a.project_level_name = '市级';
      } else if(aa.project_level == '2') {
        $scope.a.project_level_name = '省级';
      } else if(aa.project_level == '3') {
        $scope.a.project_level_name = '国家级';
      } else if(aa.project_level == '4') {
        $scope.a.project_level_name = '区域级';
      }
    }
    // 责任处室
    $scope.officeFileArr = [
      {name:'规划发展处',value:'3', id : ['8', '9']},
      {name:'行业管理处  ',value:'6', id : ['3', '4']},
      {name:'人事编制处 ',value:'1', id : ['1', '2']},
      {name:'政策法规处 ',value:'2', id : ['3', '4']},
      {name:'区域合作处',value:'4', id : ['5', '6', '7']},
      {name:'市场开发处 ',value:'5', id : ['1', '2']},
      {name:'产业发展处',value:'7', id : ['8', '9']},
      {name:'特色旅游处',value:'8', id : ['5', '6', '7']},
      {name:'旅游质量监督管理所',value:'9', id : ['3', '4']},
      {name:'旅游产业发展服务中心',value:'10', id : ['8', '9']},
      {name:'机关党委',value:'11', id : ['5', '6', '7']},
      {name:'办公室',value:'12', id : ['5', '6', '7']}
    ]
    $scope.getRecommendName = function(recommend_type){
      for(var i = 0; i < $scope.officeFileArr.length; i++){
        var array = $scope.officeFileArr[i].id;
        array.forEach(element => {
          if(recommend_type == element){
            $scope.a.recommend_type_name = $scope.officeFileArr[i].name;
            console.log($scope.officeFileArr[i].name);
          }
        });
      }
    }
    // 公告类型
    $scope.typeFileArr = [
        {name:'王者类型',value:'1', id : '1'},
        {name:'青铜',value:'2', id : '2'},
        {name:'白银',value:'3', id : '3'},
        {name:'王者类型1',value:'4', id : '4'},
        {name:'青铜1',value:'5', id : '5'},
        {name:'白银1',value:'6', id : '6'},
        {name:'王者类型2',value:'7', id : '7'},
        {name:'青铜2',value:'8', id : '8'},
        {name:'白银2',value:'9', id : '9'}        
    ]
    $scope.getGuideType = function(guide_type){
        $scope.typeFileArr.forEach(element => {
          if(guide_type == element.value){
            $scope.a.project_type_name = element.name;
          }
        });
    }
    // $scope.del=function(index, number, str){
    //   console.log(index, number, str);
    //   for(var i = 0; i < $scope.arr.length; i++){
    //     if(str == $scope.arr[i].dir){
    //       $scope.array.splice(i,1);
    //     }
    //   }
    //   console.log($scope.arr);
    // }
    // $scope.arr = [];
    // var dic = {};
    // $scope.image = function(aa){
    //   var para = $state.get('app.imageupload');
    //   //设置上传文件夹，以自己业务命名
    //   angular.extend(para, {
    //     resolve : {  
    //       'dir' : function(){
    //         return 't1';
    //       }
    //     } 
    //   })
    //   var modalInstance = $modal.open(para);
    //   modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
    //     console.log('modal is opened');  
    //   });  
    //   modalInstance.result.then(function(result) {  
    //     if(aa == '1'){ // 材料1
    //       $scope.array1 = result;
    //       dic.aa = $scope.array1;
    //       console.log(dic);
    //     } else if(aa == '2'){
    //       $scope.array2 = result;
    //       dic.bb = $scope.array2;
    //       console.log(dic);
    //     } else if(aa == '3'){
    //       $scope.array3 = result;
    //       dic.cc = $scope.array3;
    //       console.log(dic);
    //     } else if(aa == '4'){
    //       $scope.array4 = result;
    //       dic.dd = $scope.array4;
    //       console.log(dic);
    //     } else if(aa == '5'){
    //       $scope.array5 = result;
    //       dic.ee = $scope.array5;
    //       console.log(dic);
    //     } else if(aa == '6'){
    //       $scope.array6 = result;
    //       dic.ff = $scope.array6;
    //       console.log(dic);
    //     } else if(aa == '7'){
    //       $scope.array7 = result;
    //       dic.gg = $scope.array7;
    //       console.log(dic);
    //     }
    //     // $scope.a.project_file = $scope.array.join(',');
    //   }, function(reason) {  
    //     console.log(reason);// 点击空白区域，总会输出backdrop  
    //     // click，点击取消，则会暑促cancel  
    //     $log.info('Modal dismissed at: ' + new Date());  
    //   }); 
    // };
    // 提交
    $scope.submit = function(){
      // console.log(dic);
      // console.log(JSON.stringify(dic));
      console.log($scope.a);
      // $scope.a.project_file = JSON.stringify(dic);
        if($scope.a.project_name==null||$scope.a.project_name==''||$scope.a.project_name==undefined){
            alert('请填写项目名称');
            return;
        }
        // if($scope.a.project_file==null||$scope.a.project_file==''||$scope.a.project_file==undefined){
        //     alert('请上报材料');
        //     return;
        // }
        $resource('/api/ac/ggc/reviewCompanyProjectService/createCompanyProject', {}, {}).save($scope.a, function(res){
            if(res.errcode === 0){ 
                toaster.success({title:"",body:'操作成功'});
                $state.go('app.declarationList', {'type' : '0'});
            }else{
                toaster.error({title:"",body:res.errmsg});
            }
        });
      }
    
};
